package com.wxj.bank.module.utils;


import com.wxj.bank.module.constant.Constants;
import com.wxj.bank.module.exceptions.BankException;
import org.omg.CORBA.SystemException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * @author shengtao
 * @Description: redis key工具类
 * @date 2019/01/30 10:50
 */
public class RedisKeyUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(RedisKeyUtils.class);

    public static String genKey(Object... keys) {
        if (null == keys || keys.length <= 0) {
            LOGGER.error("keys不能为空");
            throw new BankException("9999", "keys不能为空");
        }
        StringBuffer keyBuffer = new StringBuffer();
        for (int i = 0; i < keys.length; i++) {
            keyBuffer.append(keys[i]);
            if (i < keys.length - 1) {
                keyBuffer.append(Constants.SYMBOL_COLON);
            }

        }
        return keyBuffer.toString();
    }

     /**
     * 转换时间key 201807261730
     * @param date
     * @return
     * */

    public static String getDateTimeByMinute(Date date) {
        String dateTime = DateUtils.dateToString(date, DateUtils.DATE_PATTERN_YYYYMMDDHHMM);
        return String.format("%s%d", new Object[]{dateTime.substring(0, 11), Integer.valueOf(0)});
    }

}
